package com.b2.controller.wx;

import com.b2.pojo.dto.addParentDto;
import com.b2.pojo.entity.Parent;
import com.b2.pojo.entity.Teacher;
import com.b2.result.Result;
import com.b2.service.ParentService;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/wx/parent")
@Slf4j
@Api(tags = "微信家长相关接口")
@CrossOrigin
public class ParentController {

    @Autowired
    ParentService parentService;
    //家长通过邀请码创建身份信息
    @PostMapping("addparent")
    @ApiOperation(value = "家长通过邀请码创建身份信息")
    public Result addparent(@RequestBody addParentDto parent){
        parentService.addparent(parent);
        return Result.success();
    }

    /**
     * 根据手机号查询家长姓名
     * @param phone
     * @return
     */
    @ApiOperation("根据手机号查询家长姓名")
    @PostMapping("/selectNameByPhone")
    public Result<String> selectName(String phone){
        if (phone == null){
            return Result.error("手机号不能为空");
        }
        Parent parent = parentService.getOne(Wrappers.<Parent>lambdaQuery().eq(Parent::getPhone, phone));

        return Result.success(parent.getName());
    }
}
